package com.scuec.trainingmanagementsys.mapper;
import com.scuec.trainingmanagementsys.entity.Assessment;
import org.apache.ibatis.annotations.*;
import java.util.List;
import java.util.Map;

public interface AssessmentMapper {
    // 增加评估记录
    @Insert("INSERT INTO assessment (assessmentcontent, teacherID, ascreatetime, dailyreportid) " +
            "VALUES (#{assessmentContent}, #{teacherID}, #{asCreateTime}, #{dailyReportID})")
    @Options(useGeneratedKeys = true, keyProperty = "assessmentID", keyColumn = "assessmentid")
    int addAssessment(Assessment assessment);

    // 删除评估记录
    @Delete("DELETE FROM assessment WHERE assessmentid = #{assessmentID}")
    int deleteAssessmentById(Integer assessmentID);

    // 根据ID查找评估记录
    @Select("SELECT * FROM assessment WHERE assessmentid = #{assessmentID}")
    Assessment findAssessmentById(Integer assessmentID);

    // 查找所有评估记录
    @Select("SELECT * FROM assessment")
    List<Assessment> findAllAssessments();

    // 根据教师ID查找评估记录
    @Select("SELECT * FROM assessment WHERE teacherid = #{teacherID}")
    List<Assessment> findAssessmentsByTeacherId(Integer teacherID);

    // 修改评估记录（新增）
    @Update("UPDATE assessment " +
            "SET assessmentcontent = #{assessmentContent}, " +
            "teacherid = #{teacherID}, " +
            "ascreatetime = #{asCreateTime}, " +
            "dailyreportid = #{dailyReportID} " +
            "WHERE assessmentid = #{assessmentID}")
    int updateAssessment(Assessment assessment);

    @Select("SELECT * FROM assessment WHERE dailyreportid = #{dailyReportID}")
    List<Assessment> findAssessmentsByDailyReportID(Integer dailyReportID);

    // 根据日报ID查找评估记录，并关联教师表获取教师姓名、评语内容和评语发布时间
    @Select("SELECT a.assessmentID, a.assessmentContent, a.asCreateTime, t.teacherName " +
            "FROM assessment a " +
            "LEFT JOIN teacher t ON a.teacherID = t.teacherID " +
            "WHERE a.dailyreportid = #{dailyReportID}")
    List<Map<String, Object>> findAssessmentsByDailyReportIDWithDetails(Integer dailyReportID);
}